<?php
# ============================================================================
# 版权所有  Chilcoo.com，并保留所有权利。
# 网站地址: http://www.chilcoo.com/erphp
# ----------------------------------------------------------------------------
# 这不是一个自由软件！你不能通过任何方式破解本软件.
# 使用:不允许对程序代码以任何形式任何目的的再发布。
# ============================================================================
# $Author: Chilcoo Inc. *
# $Official website : www.chilcoo.com
# 
# 文件信息:
# File : /money.inc.php
# 金钱管理

class money{
	# 数据库套件
	private $database;
	# 存款
	public $deposit = 0;
	# 取款
	public $draw = 0;
	function __construct(){
		$this->database = new db(config::conf_db_host,config::conf_db_user,
			config::conf_db_password,config::conf_db_name);
	}
	function sum_all(){
		$sql = "SELECT payment,SUM(account) AS account FROM cs2_money 
			GROUP BY payment ORDER BY payment ASC;";
		$rows = $this->database->select($sql);
		$deposit = $rows[0]['account'];
		$draw = $rows[1]['account'];
		return $rows;
	}
	function sum_bank(){
		$sql = "SELECT cs2_bank.bank,cs2_bank.branch,cs2_bank.bankno,cs2_bank.name,way,
			SUM(IF(payment=0, account,0)) AS accountin,
			SUM(IF(payment=1, account,0)) AS accountout
			 FROM cs2_money LEFT OUTER JOIN cs2_bank
			ON (cs2_bank.bankId=cs2_money.way) 
			GROUP BY way ORDER BY way ASC;";
		$rows = $this->database->select($sql);
		return $rows;
	}
	function sum_bank_by_dates(){
		$sql = "SELECT SUM(IF(`use`=1, IF(payment=1, -1 * account, account),0)) AS account1,
					SUM(IF(`use`=11, IF(payment=1, -1 * account, account),0)) AS account11,
					SUM(IF(`use`=2, IF(payment=1, -1 * account, account),0)) AS account2,
					SUM(IF(`use`=3, IF(payment=1, -1 * account, account),0)) AS account3,
					SUM(IF(`use`=6, IF(payment=1, -1 * account, account),0)) AS account6,
					month(dates) AS dmonth,year(dates) AS dyear
			FROM cs2_money WHERE (year(dates) = year(curdate()) OR year(dates) = year(curdate())-1) 
			GROUP BY month(dates) ORDER BY dyear DESC,dmonth DESC;";
		$rows = $this->database->select($sql);
		return $rows;
	}
}

$_money = new money();
?>